package cn.bonoon.services.plugins;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.bonoon.core.plugins.LogService;
import cn.bonoon.entities.LogEntity;
import cn.bonoon.kernel.events.OperateEvent;
import cn.bonoon.kernel.support.services.AbstractSearchService;

@Service
@Transactional(readOnly = true)
public class LogServiceImpl extends AbstractSearchService<LogEntity> implements LogService {

	@Override
	@Transactional
	public void log(LogEntity entity) {
		entityManager.persist(entity);
	}

	@Override
	@Transactional
	public void log(OperateEvent event, String content) {
		LogEntity log = new LogEntity();
		log.setContent(content);
		log.setCreateAt(event.now());
		log.setCreatorId(event.getId());
		log.setOwnerId(event.toOwnerId());
		log.setLoginName(event.getUsername());
		log.setUserName(event.getDisplayName());
		entityManager.persist(log);
	}
}
